package com.kfm.dao;

import com.kfm.model.FileDO;
import com.kfm.util.DBUtil;

import java.util.List;

public class FileDao {

    private DBUtil dbUtil = new DBUtil();

    public int save(FileDO fileDO){
        String sql = "insert into file (name, path, url, size) values(?, ?, ?, ?)";
        return dbUtil.update(sql, fileDO.getName(), fileDO.getPath(), fileDO.getUrl(), fileDO.getSize());
    }


    public FileDO selectById(Integer id){
        String sql = "select * from file where id = ?";
        return dbUtil.queryOne(sql, FileDO.class, id);
    }

    public int saveWithKey(FileDO fileDO){
        String sql = "insert into file (name, path, url, size) values(?, ?, ?, ?)";
        return dbUtil.saveWithKey(sql, fileDO.getName(), fileDO.getPath(), fileDO.getUrl(), fileDO.getSize());
    }


    public int updateUrlById(Integer id, String url){
        String sql = "update file set url = ? where id = ?";
        return dbUtil.update(sql, url, id);
    }

    public List<FileDO> selectAll(){
        String sql = "select * from file";
        return dbUtil.query(sql, FileDO.class);
    }
}
